// pages/admin/plugins/feedback/details/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    // 进入位置 转单记录:3
    type: 0,
    info: {},
  },

  // 获取反馈详情
  loadFeedbackDetails() {
    var that = this;
    var params = {
      point_url: app.server.adminApi.getSuperWorkOrderDetails,
      id: this.data.id
    }
    app.server.getConnect(params).then(function(res) {
      that.setData({
        info: res.data
      })
    })
  },

  toAccept() {
    var that = this;
    var params = {
      point_url: app.server.adminApi.doAcceptSuperWorkOrder,
      id: this.data.id
    }
    app.server.getConnect(params).then(function(res) {
      wx.showToast({
        title: '签收成功~',
      })
      that.loadFeedbackDetails();
    })
  },

  toReply() {
    wx.navigateTo({
      url: '/pages/admin/plugins/superWorkOrder/reply/index?id=' + this.data.id,
    })
  },

  toTransfer() {
    wx.navigateTo({
      url: '/pages/admin/plugins/superWorkOrder/transfer/index?id=' + this.data.id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: options.id,
      type: options.type
    });
  },

  //浏览图片
  preview: function (e) {
    console.log(e)
    let src = e.currentTarget.dataset.src;
    wx.previewImage({
      urls: src,
      current: src[0]
    })
  },

  innerAudioContext: null,
  // 播放声音
  playVoice(e) {
    let that = this;
    this.innerAudioContext = wx.createInnerAudioContext();
    this.innerAudioContext.src = e.currentTarget.dataset.url;
    this.innerAudioContext.play();
    this.innerAudioContext.onError((res) => {
      console.log(res.errMsg)
      console.log(res.errCode)
    });
  },

  // 查看文档
  openFile(e){
    wx.showLoading({
      title: '下载中...',
      mask: true
    })
    wx.downloadFile({
      url: e.currentTarget.dataset.file.url,
      success: function (res) {
        wx.hideLoading();
        var filePath = res.tempFilePath;
        console.log(res)
        //页面显示加载动画
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            console.log('打开文档成功')
          }
        })
      },
      fail: function(res) {
        wx.hideLoading();
        console.log(res);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    app.pageOnloadInit(this, app);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.loadFeedbackDetails();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    app.pageOnloadInit(this, app);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})